﻿Imports System.Data.SqlClient

Public Class clsCTES_PROV
    Private mintIdCteProv As Integer
    Public Property ID_CTEPROV() As Integer
        Get
            Return mintIdCteProv
        End Get
        Set(ByVal value As Integer)
            mintIdCteProv = value
        End Set
    End Property
    Public Sub New()
        mintIdCteProv = 0
    End Sub

    Public Function INSERTA_CTEPROV(ByVal CODIGO As String, ByVal NOMBRE As String, ByVal FECHA As Date, ByVal RFC As String, ByVal CURP As String, ByVal DEMOM As String, ByVal REPRESENTANTE As String, ByVal IDMONEDA As Integer, ByVal DESCUENTO As Double, ByVal CRDITO As Integer, ByVal CLASIF1 As String, ByVal CLASIF2 As String, ByVal CLASIF3 As String, ByVal LIMITE As Double, ByVal DIAS As Integer, ByVal EXCEDE As Integer, ByVal NOTAS As String, ByVal SAE As String, ByVal IDIOMA As String, ByVal CLIENTE As Integer, ByVal PROVEEDOR As Integer, ByVal ESTATUS As Integer)
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand("sp_CTES_PROV", cnConn)
        Command.CommandType = CommandType.StoredProcedure

        Command.Parameters.Add(New SqlParameter("@CODIGO", SqlDbType.VarChar, 30))
        Command.Parameters("@CODIGO").Value = CODIGO
        Command.Parameters.Add(New SqlParameter("@NOMBRE", SqlDbType.VarChar, 150))
        Command.Parameters("@NOMBRE").Value = NOMBRE
        Command.Parameters.Add(New SqlParameter("@FECHA", SqlDbType.DateTime))
        Command.Parameters("@FECHA").Value = FECHA
        Command.Parameters.Add(New SqlParameter("@RFC", SqlDbType.VarChar, 20))
        Command.Parameters("@RFC").Value = RFC
        Command.Parameters.Add(New SqlParameter("@CURP", SqlDbType.VarChar, 20))
        Command.Parameters("@CURP").Value = CURP
        Command.Parameters.Add(New SqlParameter("@DENOM", SqlDbType.VarChar, 150))
        Command.Parameters("@DENOM").Value = DEMOM
        Command.Parameters.Add(New SqlParameter("@REPLEGAL", SqlDbType.VarChar, 150))
        Command.Parameters("@REPLEGAL").Value = REPRESENTANTE
        Command.Parameters.Add(New SqlParameter("@IDMONEDA", SqlDbType.Int))
        Command.Parameters("@IDMONEDA").Value = IDMONEDA
        Command.Parameters.Add(New SqlParameter("@DESCUENTO", SqlDbType.Decimal))
        Command.Parameters("@DESCUENTO").Value = DESCUENTO
        Command.Parameters.Add(New SqlParameter("@CREDITO", SqlDbType.Int))
        Command.Parameters("@CREDITO").Value = CRDITO
        Command.Parameters.Add(New SqlParameter("@CLASIF1", SqlDbType.VarChar, 100))
        Command.Parameters("@CLASIF1").Value = CLASIF1
        Command.Parameters.Add(New SqlParameter("@CLASIF2", SqlDbType.VarChar, 100))
        Command.Parameters("@CLASIF2").Value = CLASIF2
        Command.Parameters.Add(New SqlParameter("@CLASIF3", SqlDbType.VarChar, 100))
        Command.Parameters("@CLASIF3").Value = CLASIF3
        Command.Parameters.Add(New SqlParameter("@LIMITE", SqlDbType.Decimal))
        Command.Parameters("@LIMITE").Value = LIMITE
        Command.Parameters.Add(New SqlParameter("@DIAS", SqlDbType.Int))
        Command.Parameters("@DIAS").Value = DIAS
        Command.Parameters.Add(New SqlParameter("@EXCEDE", SqlDbType.Int))
        Command.Parameters("@EXCEDE").Value = EXCEDE
        Command.Parameters.Add(New SqlParameter("@NOTAS", SqlDbType.VarChar, 1000))
        Command.Parameters("@NOTAS").Value = NOTAS
        Command.Parameters.Add(New SqlParameter("@SAE", SqlDbType.VarChar, 30))
        Command.Parameters("@SAE").Value = SAE
        Command.Parameters.Add(New SqlParameter("@IDIOMA", SqlDbType.VarChar, 30))
        Command.Parameters("@IDIOMA").Value = IDIOMA
        Command.Parameters.Add(New SqlParameter("@CLIENTE", SqlDbType.Int))
        Command.Parameters("@CLIENTE").Value = CLIENTE
        Command.Parameters.Add(New SqlParameter("@PROVEEDOR", SqlDbType.Int))
        Command.Parameters("@PROVEEDOR").Value = PROVEEDOR
        Command.Parameters.Add(New SqlParameter("@NOMBRE_USUARIO", SqlDbType.VarChar, 50))
        Command.Parameters("@NOMBRE_USUARIO").Value = UsuarioActivo
        Command.Parameters.Add(New SqlParameter("@ESTATUS", SqlDbType.Int))
        Command.Parameters("@ESTATUS").Value = ESTATUS
        Command.Parameters.Add(New SqlParameter("@NUM_CLASIF1", SqlDbType.Int))
        Command.Parameters.Add(New SqlParameter("@NUM_CLASIF2", SqlDbType.Int))
        Command.Parameters.Add(New SqlParameter("@NUM_CLASIF3", SqlDbType.Int))
        If CLIENTE = 1 Then
            Command.Parameters("@NUM_CLASIF1").Value = CLASIFICACIONES_CLIENTES.Clasificacion_1
            Command.Parameters("@NUM_CLASIF2").Value = CLASIFICACIONES_CLIENTES.Clasificacion_2
            Command.Parameters("@NUM_CLASIF3").Value = CLASIFICACIONES_CLIENTES.Clasificacion_3
        Else
            Command.Parameters("@NUM_CLASIF1").Value = CLASIFICACIONES_PROVEEDORES.Clasificacion_1
            Command.Parameters("@NUM_CLASIF2").Value = CLASIFICACIONES_PROVEEDORES.Clasificacion_2
            Command.Parameters("@NUM_CLASIF3").Value = CLASIFICACIONES_PROVEEDORES.Clasificacion_3
        End If

        Try
            cnConn.Open()
            Dim Lector As SqlDataReader

            Lector = Command.ExecuteReader()
            If Lector.Read() Then
                INSERTA_CTEPROV = Lector
                mintIdCteProv = Lector("IDPROVEEDOR")
            End If
        Catch ex As Exception
            INSERTA_CTEPROV = -1
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try


    End Function
    Public Function INSERTA_DIRECCION(ByVal TIPO_CAT As Integer, ByVal CALLE As String, ByVal COLONIA As String, ByVal POSTAL As String, ByVal TEL1 As String, ByVal CEL As String, ByVal FAX As String, ByVal MAIL As String, ByVal WEB As String, ByVal FTP As Double, ByVal PAIS As Integer, ByVal ESTADO As Integer, ByVal CIUDAD As String, ByVal IDCTE As Integer, ByVal TIPO_DIR As Integer)
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand("sp_DIRECCIONES", cnConn)
        Command.CommandType = CommandType.StoredProcedure

        Command.Parameters.Add(New SqlParameter("@TIPO_CAT", SqlDbType.Int))
        Command.Parameters("@TIPO_CAT").Value = TIPO_CAT
        Command.Parameters.Add(New SqlParameter("@CALLE", SqlDbType.VarChar, 150))
        Command.Parameters("@CALLE").Value = CALLE
        Command.Parameters.Add(New SqlParameter("@COLONIA", SqlDbType.VarChar, 30))
        Command.Parameters("@COLONIA").Value = COLONIA
        Command.Parameters.Add(New SqlParameter("@PAIS", SqlDbType.DateTime))
        Command.Parameters("@PAIS").Value = PAIS
        Command.Parameters.Add(New SqlParameter("@ESTADO", SqlDbType.VarChar, 20))
        Command.Parameters("@ESTADO").Value = ESTADO
        Command.Parameters.Add(New SqlParameter("@CIUDAD", SqlDbType.VarChar, 20))
        Command.Parameters("@CIUDAD").Value = CIUDAD
        Command.Parameters.Add(New SqlParameter("@CP", SqlDbType.VarChar, 150))
        Command.Parameters("@CP").Value = POSTAL
        Command.Parameters.Add(New SqlParameter("@TELEFONO", SqlDbType.VarChar, 150))
        Command.Parameters("@TELEFONO").Value = TEL1
        Command.Parameters.Add(New SqlParameter("@CEL", SqlDbType.VarChar, 150))
        Command.Parameters("@CEL").Value = CEL
        Command.Parameters.Add(New SqlParameter("@FAX", SqlDbType.VarChar, 150))
        Command.Parameters("@FAX").Value = FAX
        Command.Parameters.Add(New SqlParameter("@MAIL", SqlDbType.VarChar, 150))
        Command.Parameters("@MAIL").Value = MAIL
        Command.Parameters.Add(New SqlParameter("@WEB", SqlDbType.VarChar, 150))
        Command.Parameters("@WEB").Value = WEB
        Command.Parameters.Add(New SqlParameter("@FTP", SqlDbType.VarChar, 150))
        Command.Parameters("@FTP").Value = FTP
        Command.Parameters.Add(New SqlParameter("@TIPO", SqlDbType.Int))
        Command.Parameters("@TIPO").Value = TIPO_DIR
        Command.Parameters.Add(New SqlParameter("@NOMBRE_USUARIO", SqlDbType.VarChar, 50))
        Command.Parameters("@NOMBRE_USUARIO").Value = UsuarioActivo
        Command.Parameters.Add(New SqlParameter("@IDCTEPROV", SqlDbType.Int))
        Command.Parameters("@IDCTEPROV").Value = mintIdCteProv

        Try
            cnConn.Open()
            Dim Lector As SqlDataReader

            Lector = Command.ExecuteReader()
            If Lector.Read() Then
                INSERTA_DIRECCION = Lector
            End If
        Catch ex As Exception
            INSERTA_DIRECCION = -1
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try


    End Function
    Sub INSERTA_SUCURSAL(ByVal IDCLIENTE As Integer, ByVal CLAVE As String, ByVal DESCRIPCION As String)
        Dim sql As String = "Insert Into SUCURSALES VALUES (" & _
                       "@IDCLIENTE," & _
                       "@CLAVE," & _
                       "@DESCRIPCION)"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IDCLIENTE", IDCLIENTE)
        Command.Parameters.AddWithValue("CLAVE", CLAVE)
        Command.Parameters.AddWithValue("DESCRIPCION", DESCRIPCION)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
            If RowsAffected > 0 Then
                cnConn.Close()
            Else
                If cnConn.State = ConnectionState.Open Then
                    cnConn.Close()
                End If
            End If
        Catch ex As Exception
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try
    End Sub
End Class
